package dpll.run;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;

import dpll.ast.ASTVisitor;
import dpll.ast.IASTNode;
import dpll.fnc.FNCVisitor;
import dpll.fnc.IVisitor;
import dpll.parser.logpropBaseVisitor;
import dpll.parser.logpropLexer;
import dpll.parser.logpropParser;
import dpll.parser.logpropParser.FormulasContext;

public class Proceso {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @throws UnsupportedEncodingException 
	 */
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
		final ANTLRInputStream is = new ANTLRInputStream(new InputStreamReader(new FileInputStream(args[0]), "UTF-8"));
        final logpropLexer lexer = new logpropLexer(is);
        final CommonTokenStream ts = new CommonTokenStream(lexer);
        final logpropParser parser = new logpropParser(ts);
        final FormulasContext formulas = parser.formulas();

        final logpropBaseVisitor<IASTNode> visitor = new ASTVisitor();
        final IASTNode astTree = visitor.visit(formulas);
        System.out.println(astTree.toString());
        
        final IVisitor<IASTNode> fncVisitor = new FNCVisitor();
        IASTNode fncTree = fncVisitor.visit(astTree);
        while (fncVisitor.isCambio()) {
        	fncVisitor.setCambio(false);
        	fncTree = fncVisitor.visit(fncTree);
        }
        System.out.println(fncTree.toString());
        
	}

}
